<?php
namespace App\Http\Controllers\AppApi\My;

use App\Services\Admin\JobCompanyService;
use App\Services\Admin\NewsService;
use App\Services\Admin\OrderBaleService;
use Illuminate\Http\Request;

class MyPubController extends BaseController
{
    /**
     * 发布接口
     * 制作者：九哥
     */

    protected $bale;
    protected $job;
    protected $news;

    public function __construct()
    {
        parent::__construct();
        $this->bale = new OrderBaleService();
        $this->job = new JobCompanyService();
        $this->news = new NewsService();
    }

    /**
     * 发布的货物订单
     * /api/my/pub/order-get
     */
    public function getOrderList(Request $request)
    {
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $page = isset($request->page) ? $request->page : 1;
        if (!$token) {
            return $this->toJson(-2);
        }
       /// $page--;
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $models = $this->bale->getBalesByCid($uid,$page);
        if (!count($models)) { return $this->toJson(-3); }
        $dataArr = $models;
        return $this->toJson(0,$dataArr);
    }

    /**
     * 发布的招聘
     * /api/my/pub/job-get
     */
    public function getJobList(Request $request)
    {
     //   exit('aaaaaaaa');
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $page = isset($request->page) ? $request->page : 1;
        $page--;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $dataArr = $this->job->getJobsByCid($uid,$page);
        if (!$dataArr) { return $this->toJson(-3); }
        return $this->toJson(0,$dataArr);
    }

    /**
     * 发布的资讯
     * /api/my/pub/news-get
     */
    public function getNewsList(Request $request)
    {
     ///    exit('aaaaaaaaaa');
        if ($request->app_access!=$this->app_access) {
            return $this->toJson(-1);
        }
        $token = $request->token;
        $page = isset($request->page) ? $request->page : 0;///$page--;
        if (!$token) {
            return $this->toJson(-2);
        }
        $uid = $this->accessGet($token);
        if (!$uid) { return $this->toJson(-13); }
        $models = $this->news->getIndexByCid($uid,$page);
        if (!count($models)) { return $this->toJson(-3); }
        $dataArr = $models;
        return $this->toJson(0,$dataArr);
    }
}